package com.glsc.ngateway.common.base.dto.opmanage.report.subscribe;

import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.subscribe.ReportParamConfig;
import smartbi.sdk.service.simplereport.NameValuePair;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: qiyr
 * @date: 2022/6/7 13:34
 * @description: 报表可配置参数Dto
 */
public class ReportParamConfigDto extends ReportParamConfig {

    /**
     * 报表参数备选值
     */
    private Map<String, String> reportParamValueMap;

    public ReportParamConfigDto() {
    }

    public ReportParamConfigDto(ReportParamConfig reportParamConfig) {
        super(reportParamConfig.getReportId(), reportParamConfig.getParamKey(), reportParamConfig.getParamValue(),
                reportParamConfig.getParamType(), reportParamConfig.getComponentType(),
                reportParamConfig.getComponentProperty(), reportParamConfig.getDateFlag());
    }

    public ReportParamConfigDto(ReportParamConfig reportParamConfig, Map<String, String> reportParamValueMap) {
        super(reportParamConfig.getReportId(), reportParamConfig.getParamKey(), reportParamConfig.getParamValue(),
                reportParamConfig.getParamType(), reportParamConfig.getComponentType(),
                reportParamConfig.getComponentProperty(), reportParamConfig.getDateFlag());
        this.reportParamValueMap = reportParamValueMap;
    }

    public Map<String, String> getReportParamValueMap() {
        return reportParamValueMap;
    }

    public void setReportParamValueMap(Map<String, String> reportParamValueMap) {
        this.reportParamValueMap = reportParamValueMap;
    }

    public ReportParamDto toReportParamDto() {
        ReportParamDto paramDto = new ReportParamDto();
        paramDto.setName(this.getParamKey());
        paramDto.setDateFlag(this.getDateFlag());
        paramDto.setDateFormat(this.getParamType());
        List<NameValuePair> nameValuePairList = new ArrayList<>();
        reportParamValueMap.forEach((k, v) -> {
            NameValuePair pair = new NameValuePair();
            pair.setValue(k);
            pair.setName(v);
            nameValuePairList.add(pair);
        });
        paramDto.setNameValuePairList(nameValuePairList);
        return paramDto;
    }
}
